﻿/*
** Xin YUAN, 2023, BSD (2)
*/

////////////////////////////////////////////////////////////////////////////////

#include "base/_w_socket.h"

////////////////////////////////////////////////////////////////////////////////

//socket_support

//Define a local variable of this class in the front of main function.

class socket_support
{
public:
	socket_support() noexcept
	{
	}
	socket_support(const socket_support&) = delete;
	~socket_support() noexcept
	{
	}

	socket_support& operator=(const socket_support&) = delete;

	bool Initialize() noexcept
	{
		return SUCCEEDED(m_ss.Initialize(MAKE_WINSOCK_VERSION(2, 2)));
	}

protected:
	_w_socket_support m_ss;
};

//ns_socket

class ns_socket
{
public:
	ns_socket() noexcept
	{
	}
	ns_socket(const ns_socket&) = delete;
	ns_socket(ns_socket&& src) noexcept : m_sock(rv_forward(src.m_sock))
	{
	}
	~ns_socket() noexcept
	{
	}

	ns_socket& operator=(const ns_socket&) = delete;
	ns_socket& operator=(ns_socket&& src) noexcept
	{
		m_sock = rv_forward(src.m_sock);
		return *this;
	}

	//for internal usage
	const _w_async_socket& GetSocket() const noexcept
	{
		return m_sock;
	}
	_w_async_socket& GetSocket() noexcept
	{
		return m_sock;
	}

protected:
	_w_async_socket m_sock;
};

////////////////////////////////////////////////////////////////////////////////
